﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TamTreSoSinh.DBContext;

namespace TamTreSoSinh.UC
{
    public partial class OurServicePart : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            LoadData();
        }

        private void LoadData()
        {
            DBTamTreEntities dataContext = new DBTamTreEntities();
            List<OurService> listOurService = dataContext.OurServices.Where(obj => obj.IsOnHomePage && obj.ServiceCategory.IsVisible).OrderBy(obj => obj.ServiceCategory.Priority).ThenBy(obj => obj.Priority).ToList();
            

            rptService.DataSource = listOurService;
            rptService.DataBind();
        }

        protected void rptService_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            HyperLink hpl;
            OurService ourService = (OurService)e.Item.DataItem;
            hpl = (HyperLink)e.Item.FindControl("hplImgService");
            hpl.ImageUrl = ourService.MainImage;
            hpl.NavigateUrl = "/ServiceDetailPage.aspx?Id=" + ourService.Id;

            hpl = (HyperLink)e.Item.FindControl("hplTitleService");
            hpl.Text = ourService.Title;
            hpl.NavigateUrl = "/ServiceDetailPage.aspx?Id=" + ourService.Id;
        }

    }
}